package com.blb.javatest02.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.javatest02.entity.Attend;
import com.blb.javatest02.entity.ResponseResult;
import com.blb.javatest02.service.IAttendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenheng
 * @since 2023-11-27
 */
@CrossOrigin
@RestController
public class AttendController {

    @Autowired
    private IAttendService attendService;

    @GetMapping("attend-page")
    public ResponseResult<Page<Attend>> getAttendPage(@RequestParam(required = false,defaultValue = "1") Long current,
                                                      @RequestParam(required = false,defaultValue = "5") Long size){
        Page<Attend> page = attendService.getAttendPage(current, size);
        return ResponseResult.ok(page);
    }

    @PostMapping("/attend")
    public ResponseResult<String> saveAttend(@RequestBody Attend attend){
        attendService.save(attend);
        return ResponseResult.ok("ok");
    }

    @PutMapping("/attend")
    public ResponseResult<String> updateAttend(@RequestBody Attend attend){
        attendService.updateById(attend);
        return ResponseResult.ok("ok");
    }

    @DeleteMapping("/attend/{id}")
    public ResponseResult<String> deleteAttend(@PathVariable Long id){
        attendService.removeById(id);
        return ResponseResult.ok("ok");
    }
}
